package com.zhenhao.xsq.ui.activity.user;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.zhenhao.xsq.R;
import com.zhenhao.xsq.adapter.door.DoorManageAdapter;
import com.zhenhao.xsq.adapter.user.UserManageAdapter;
import com.zhenhao.xsq.application.AppConfig;
import com.zhenhao.xsq.base.BaseActivity;
import com.zhenhao.xsq.ui.activity.user.component.DaggerUserManagerComponent;
import com.zhenhao.xsq.ui.activity.user.contract.UserManagerContract;
import com.zhenhao.xsq.ui.activity.user.module.UserManagerModule;
import com.zhenhao.xsq.ui.activity.user.presenter.UserManagerPresenter;
import com.zhenhao.xsq.utils.SpSaveUtils;
import com.zhenhao.xsq.utils.TimeUtil;
import com.zhenhao.xsq.utils.ToastUtil;
import com.zhenhao.xsq.utils.UIUtils;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;

public class UserManagerActivity extends BaseActivity implements UserManagerContract.View {

    @Inject
    UserManagerPresenter mPresenter;

    @BindView(R.id.rv)
    RecyclerView rv;
    @BindView(R.id.srl)
    SmartRefreshLayout srl;
    @BindView(R.id.iv_head)
    ImageView ivHead;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_phone)
    TextView tvPhone;

    private String TAG = "UserManagerActivity";

    private UserManageAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void initView() {
        setContentView(R.layout.activity_user_manager);
        ButterKnife.bind(this);
//        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        setToolbarTitle("住户管理");

        autolayout.setBackgroundColor(ContextCompat.getColor(this, R.color.color_00000000));
        mToolbar.setBackgroundColor(ContextCompat.getColor(this, R.color.color_00000000));
        rootLayout.setBackground(ContextCompat.getDrawable(this, R.mipmap.bg_activity_base));
        toolbarTitle.setTextColor(ContextCompat.getColor(this, R.color.black));
        toolbarMenu.setTextColor(ContextCompat.getColor(this, R.color.color_333333));
        mToolbar.setNavigationIcon(ContextCompat.getDrawable(this, R.mipmap.toolbar_back2));

        setMenuText("添加住户", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                ToastUtil.showLong("添加住户");
                SpSaveUtils.putToolbarColor(0);
                Bundle bundle = new Bundle();
                bundle.putInt("type",1);
                startActivity(UserAddActivity.class,bundle);
            }
        });

        initRv();

    }

    private void initRv() {
        UIUtils.configRecycleView(rv, new LinearLayoutManager(this));
        adapter = new UserManageAdapter();
        rv.setAdapter(adapter);

        srl.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                srl.finishRefresh();
                srl.resetNoMoreData();

                initData();
            }
        });
    }

    @Override
    protected void initData() {
        List<String> list = new ArrayList<>();
        list.add("1");
        list.add("1");
        list.add("1");
        adapter.setNewData(list);
    }

    @Override
    protected void setupActivityComponent() {
        DaggerUserManagerComponent
                .builder()
                .appComponent(((AppConfig) getApplication()).getApplicationComponent())
                .userManagerModule(new UserManagerModule(this))
                .build()
                .inject(this);
    }

    @Override
    public void showProgressDialog() {
        progressDialog.show();
    }

    @Override
    public void closeProgressDialog() {
        progressDialog.hide();
    }

    @Override
    public void setPresenter(UserManagerContract.UserManagerContractPresenter presenter) {
        mPresenter = (UserManagerPresenter) presenter;
    }

}
